package com.c1g19.dao.common;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Map;

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.handlers.MapHandler;
import org.apache.log4j.Logger;

import com.c1g19.dao.BaseDao;
import com.c1g19.utils.BasicRowProcessorFix;
import com.c1g19.utils.DbControl;

/**
 * 用户数据库操作类
 * 
 * @author thunder
 * 
 */
public class UserDao extends BaseDao {
	private static final Logger logger = Logger.getLogger(UserDao.class);


	/**
	 * 获得用户信息
	 * 
	 * @param username
	 * @param password
	 * @return
	 */
	public Map<String, Object> getUser(String username, String password) {
		logger.info("getUser");
		Map<String, Object> userMap = null;
		Connection conn = null;
		try {
			conn = DbControl.getConnection();
			String sql = "select * from user where username=? and password=? and status = 1 ;";
			userMap = getQueryRunner().query(conn, sql,
					new MapHandler(new BasicRowProcessorFix()), username,
					password);
			logger.info("user:" + userMap);
		} catch (Exception e) {
			logger.error("", e);
		} finally {
			DbUtils.closeQuietly(conn);
		}
		return userMap;
	}
}
